package com.emotion.recognition.server.mlp;


/**
 * Activation function used by perceptrons.
 * 
 * @author Minsang
 */
public interface ActivationFunction {

    public double apply(double input);

    public double derivativeApply(double input);

    /**
     * A logistic sigmoid activation function
     */
    ActivationFunction LogSig = new ActivationFunction() {

        @Override
        public double apply(double input) {
            return 1 / (1 + Math.exp(-input));
        }

        @Override
        public double derivativeApply(double input) {
            double f = apply(input);
            return f * (1 - f);
        }
    };

    /**
     * A hyperbolic tangent sigmoid activation function
     */
    ActivationFunction TanSig = new ActivationFunction() {

        @Override
        public double apply(double input) {
            return Math.tanh(input);
        }

        @Override
        public double derivativeApply(double input) {
            return 1.0d - Math.pow(Math.tanh(input), 2.0d);
        }
    };

    ActivationFunction Linear = new ActivationFunction() {

        @Override
        public double apply(double input) {
            return input;
        }

        @Override
        public double derivativeApply(double input) {
            return 1;
        }
    };
}